VERSION 5.00
Begin VB.Form Form1 
   AutoRedraw      =   -1  'True
   BackColor       =   &H00FFC0C0&
   Caption         =   "Millivolt Source : delabs"
   ClientHeight    =   8085
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   10515
   ClipControls    =   0   'False
   FillColor       =   &H00C0C0C0&
   ForeColor       =   &H00C0C0C0&
   Icon            =   "mvs_main.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   Picture         =   "mvs_main.frx":0312
   ScaleHeight     =   8085
   ScaleWidth      =   10515
   StartUpPosition =   2  'CenterScreen
   Begin VB.ComboBox Combo2 
      BackColor       =   &H00404040&
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FFC0C0&
      Height          =   360
      ItemData        =   "mvs_main.frx":756C
      Left            =   240
      List            =   "mvs_main.frx":7579
      Style           =   2  'Dropdown List
      TabIndex        =   42
      Top             =   120
      Width           =   1215
   End
   Begin VB.Frame Frame6 
      BackColor       =   &H00808000&
      Caption         =   "Potentiometer"
      ForeColor       =   &H00FFFFC0&
      Height          =   1335
      Left            =   2400
      TabIndex        =   33
      Top             =   2520
      Width           =   4935
      Begin VB.VScrollBar VScroll3 
         Enabled         =   0   'False
         Height          =   495
         Left            =   3960
         Max             =   -5000
         Min             =   5000
         TabIndex        =   39
         Top             =   480
         Width           =   735
      End
      Begin VB.TextBox Text8 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H80000006&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   21.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   555
         Left            =   240
         Locked          =   -1  'True
         TabIndex        =   38
         Text            =   "0"
         Top             =   480
         Width           =   1695
      End
      Begin VB.VScrollBar VScroll2 
         Enabled         =   0   'False
         Height          =   495
         LargeChange     =   10
         Left            =   3000
         Max             =   -5000
         Min             =   5000
         SmallChange     =   10
         TabIndex        =   35
         Top             =   480
         Width           =   735
      End
      Begin VB.VScrollBar VScroll1 
         Enabled         =   0   'False
         Height          =   495
         LargeChange     =   100
         Left            =   2040
         Max             =   -20000
         Min             =   20000
         SmallChange     =   100
         TabIndex        =   34
         Top             =   480
         Width           =   735
      End
      Begin VB.Label Label8 
         Alignment       =   2  'Center
         BackStyle       =   0  'Transparent
         Caption         =   "Medium"
         ForeColor       =   &H00C0FFFF&
         Height          =   255
         Left            =   3000
         TabIndex        =   40
         Top             =   240
         Width           =   735
      End
      Begin VB.Label Label7 
         Alignment       =   2  'Center
         BackStyle       =   0  'Transparent
         Caption         =   "Fine"
         ForeColor       =   &H00C0FFFF&
         Height          =   255
         Left            =   3960
         TabIndex        =   37
         Top             =   240
         Width           =   735
      End
      Begin VB.Label Label6 
         Alignment       =   2  'Center
         BackStyle       =   0  'Transparent
         Caption         =   "Coarse"
         ForeColor       =   &H00C0FFFF&
         Height          =   255
         Left            =   2040
         TabIndex        =   36
         Top             =   240
         Width           =   735
      End
   End
   Begin VB.CommandButton Command11 
      Caption         =   "Port"
      Height          =   255
      Left            =   960
      TabIndex        =   28
      Top             =   5760
      Width           =   735
   End
   Begin VB.CommandButton Command10 
      Caption         =   "Probe"
      Height          =   255
      Left            =   120
      TabIndex        =   27
      Top             =   5760
      Width           =   735
   End
   Begin VB.Frame Frame4 
      BackColor       =   &H000080FF&
      Caption         =   "Power"
      ForeColor       =   &H0080FFFF&
      Height          =   1335
      Left            =   480
      TabIndex        =   25
      Top             =   6240
      Width           =   735
      Begin VB.CommandButton Command9 
         Caption         =   "ON"
         Height          =   495
         Left            =   120
         TabIndex        =   26
         Top             =   720
         Width           =   495
      End
      Begin VB.Shape Shape10 
         BackColor       =   &H000040C0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   120
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
   End
   Begin VB.Frame Frame5 
      BackColor       =   &H00008000&
      Caption         =   "Probe"
      ForeColor       =   &H00C0E0FF&
      Height          =   2415
      Left            =   240
      TabIndex        =   20
      Top             =   3000
      Visible         =   0   'False
      Width           =   1335
      Begin VB.TextBox Text11 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00400000&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   225
         Left            =   240
         Locked          =   -1  'True
         TabIndex        =   44
         Text            =   "+"
         Top             =   1320
         Width           =   255
      End
      Begin VB.TextBox Text10 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00400000&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   225
         Left            =   600
         Locked          =   -1  'True
         TabIndex        =   43
         Text            =   "hi"
         Top             =   1320
         Width           =   255
      End
      Begin VB.TextBox Text9 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00400000&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   12
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000080FF&
         Height          =   300
         Left            =   240
         Locked          =   -1  'True
         TabIndex        =   41
         Text            =   "set"
         Top             =   1680
         Width           =   855
      End
      Begin VB.CommandButton Command13 
         Caption         =   "OK"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   360
         TabIndex        =   30
         Top             =   2040
         Width           =   615
      End
      Begin VB.TextBox Text7 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00400000&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   225
         Left            =   840
         Locked          =   -1  'True
         TabIndex        =   24
         Text            =   "lo"
         Top             =   1320
         Width           =   255
      End
      Begin VB.TextBox Text6 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   12
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FF00&
         Height          =   345
         Left            =   240
         Locked          =   -1  'True
         TabIndex        =   23
         Text            =   "status"
         Top             =   600
         Width           =   855
      End
      Begin VB.TextBox Text5 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   12
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FF00&
         Height          =   345
         Left            =   240
         Locked          =   -1  'True
         TabIndex        =   22
         Text            =   "value"
         Top             =   240
         Width           =   855
      End
      Begin VB.TextBox Text4 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00000000&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   12
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FF00&
         Height          =   300
         Left            =   240
         Locked          =   -1  'True
         TabIndex        =   21
         Text            =   "digits"
         Top             =   960
         Width           =   855
      End
   End
   Begin VB.Timer Timer3 
      Enabled         =   0   'False
      Interval        =   1
      Left            =   1080
      Top             =   7680
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   10
      Left            =   120
      Top             =   7680
   End
   Begin VB.Timer Timer2 
      Enabled         =   0   'False
      Interval        =   100
      Left            =   600
      Top             =   7680
   End
   Begin VB.CommandButton Command12 
      BackColor       =   &H80000004&
      Caption         =   "Exit"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   9720
      Style           =   1  'Graphical
      TabIndex        =   19
      ToolTipText     =   "exit"
      Top             =   7800
      Width           =   735
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00800080&
      Caption         =   "Port"
      ForeColor       =   &H00C0FFFF&
      Height          =   2175
      Left            =   240
      TabIndex        =   11
      Top             =   600
      Visible         =   0   'False
      Width           =   1335
      Begin VB.CommandButton Command14 
         Appearance      =   0  'Flat
         BackColor       =   &H80000004&
         Caption         =   "OK"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   360
         Style           =   1  'Graphical
         TabIndex        =   29
         Top             =   1800
         Width           =   615
      End
      Begin VB.ComboBox Combo1 
         BackColor       =   &H00C0FFC0&
         Height          =   315
         ItemData        =   "mvs_main.frx":758C
         Left            =   240
         List            =   "mvs_main.frx":7599
         Style           =   2  'Dropdown List
         TabIndex        =   15
         Top             =   240
         Width           =   855
      End
      Begin VB.TextBox Text3 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00C0FFC0&
         ForeColor       =   &H00404000&
         Height          =   285
         Left            =   360
         Locked          =   -1  'True
         TabIndex        =   14
         Top             =   1440
         Width           =   735
      End
      Begin VB.TextBox Text2 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00C0FFC0&
         ForeColor       =   &H00404000&
         Height          =   285
         Left            =   360
         Locked          =   -1  'True
         TabIndex        =   13
         Top             =   1080
         Width           =   735
      End
      Begin VB.TextBox Text1 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00C0FFC0&
         ForeColor       =   &H00404000&
         Height          =   285
         Left            =   360
         Locked          =   -1  'True
         TabIndex        =   12
         Top             =   720
         Width           =   735
      End
      Begin VB.Label Label4 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "Cnt"
         ForeColor       =   &H00C0FFC0&
         Height          =   255
         Left            =   0
         TabIndex        =   18
         Top             =   1440
         Width           =   375
      End
      Begin VB.Label Label3 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "Inp"
         ForeColor       =   &H00C0FFC0&
         Height          =   255
         Left            =   0
         TabIndex        =   17
         Top             =   1080
         Width           =   375
      End
      Begin VB.Label Label2 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00FFC0C0&
         BackStyle       =   0  'Transparent
         Caption         =   "Out"
         ForeColor       =   &H00C0FFC0&
         Height          =   255
         Left            =   0
         TabIndex        =   16
         Top             =   720
         Width           =   375
      End
   End
   Begin VB.Frame Frame3 
      BackColor       =   &H00400000&
      Caption         =   "Output"
      ForeColor       =   &H00FFC0C0&
      Height          =   1335
      Left            =   2400
      TabIndex        =   2
      Top             =   3960
      Visible         =   0   'False
      Width           =   4935
      Begin VB.CommandButton Command1 
         Caption         =   "Q7"
         Height          =   375
         Left            =   120
         TabIndex        =   10
         Top             =   840
         Width           =   495
      End
      Begin VB.CommandButton Command8 
         Caption         =   "Q0"
         Height          =   375
         Left            =   4320
         TabIndex        =   9
         Top             =   840
         Width           =   495
      End
      Begin VB.CommandButton Command7 
         Caption         =   "Q1"
         Height          =   375
         Left            =   3720
         TabIndex        =   8
         Top             =   840
         Width           =   495
      End
      Begin VB.CommandButton Command6 
         Caption         =   "Q2"
         Height          =   375
         Left            =   3120
         TabIndex        =   7
         Top             =   840
         Width           =   495
      End
      Begin VB.CommandButton Command5 
         Caption         =   "Q3"
         Height          =   375
         Left            =   2520
         TabIndex        =   6
         Top             =   840
         Width           =   495
      End
      Begin VB.CommandButton Command4 
         Caption         =   "Q4"
         Height          =   375
         Left            =   1920
         TabIndex        =   5
         Top             =   840
         Width           =   495
      End
      Begin VB.CommandButton Command3 
         Caption         =   "Q5"
         Height          =   375
         Left            =   1320
         TabIndex        =   4
         Top             =   840
         Width           =   495
      End
      Begin VB.CommandButton Command2 
         Caption         =   "Q6"
         Height          =   375
         Left            =   720
         TabIndex        =   3
         Top             =   840
         Width           =   495
      End
      Begin VB.Shape Shape8 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   4320
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
      Begin VB.Shape Shape7 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   3720
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
      Begin VB.Shape Shape6 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   3120
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
      Begin VB.Shape Shape5 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   2520
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
      Begin VB.Shape Shape4 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   1920
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
      Begin VB.Shape Shape3 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   1320
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
      Begin VB.Shape Shape2 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   720
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
      Begin VB.Shape Shape1 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   120
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
   End
   Begin VB.Frame Frame2 
      BackColor       =   &H00800000&
      Caption         =   "Input"
      ForeColor       =   &H00C0FFFF&
      Height          =   1935
      Left            =   2400
      TabIndex        =   0
      Top             =   120
      Width           =   4935
      Begin VB.TextBox dvm_reading 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00400000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   45
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FF00&
         Height          =   1155
         Left            =   480
         Locked          =   -1  'True
         TabIndex        =   1
         Text            =   "1245"
         Top             =   360
         Width           =   3855
      End
      Begin VB.Label Label1 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BackStyle       =   0  'Transparent
         Caption         =   "OR"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000080FF&
         Height          =   255
         Left            =   0
         TabIndex        =   32
         Top             =   360
         Width           =   495
      End
      Begin VB.Label Label5 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BackStyle       =   0  'Transparent
         Caption         =   "UR"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000080FF&
         Height          =   255
         Left            =   0
         TabIndex        =   31
         Top             =   1320
         Visible         =   0   'False
         Width           =   495
      End
      Begin VB.Shape Shape9 
         BackColor       =   &H00000080&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         FillColor       =   &H00FFC0C0&
         Height          =   135
         Left            =   4440
         Shape           =   4  'Rounded Rectangle
         Top             =   480
         Width           =   375
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'Printer         Data Port        Status          Control
'LPT1            0x03bc          0x03bd          0x03be
'LPT2            0x0378          0x0379          0x037a
'LPT3            0x0278          0x0279          0x027a
Dim output_port As Integer  'for hex addr of output port as above
Dim input_port As Integer   'for hex addr of input port as above
Dim control_port As Integer 'for hex addr of control port as above
Dim read_digits As Integer
Dim read_value As Integer
Dim read_status As Integer
Dim outport_value, outport_high, pol_bit, rem_pol As Integer 'this stores the 8 bit output status
Dim latch_low, latch_low2, latch_high 'for hex values that strobes output to latch
Dim out7_flag, out6_flag, out5_flag, out4_flag, out3_flag, out2_flag, out1_flag, out0_flag
'these flags saves the high-low status of the 8 output bits
Dim pwr_flag 'this is 1 when instrument is on and 0 when off
Dim edge_detect, old_d5, old_d4, set_value
Dim digit_1, digit_2, digit_3, digit_4, digit_5, plus_minus
Dim d1_dun, d2_dun, d3_dun, d4_dun, d5_dun
Dim tog_1, tog_2 'toggle flags for buttons
Private Sub Combo1_Click() ' with this the parallel port is selected.
output_port = Combo1.Text
input_port = output_port + 1
control_port = output_port + 2
Text1.Text = "0x" & Hex(output_port)
Text2.Text = "0x" & Hex(input_port)
Text3.Text = "0x" & Hex(control_port)
End Sub

Private Sub Combo2_Click()
If Combo2.Text = "DPC" Then ' digital process controller
Frame3.Visible = True
Frame6.Visible = False
ElseIf Combo2.Text = "MVS" Then ' milli volt source
Frame3.Visible = False
Frame6.Visible = True
Else
Frame3.Visible = False ' digital volt meter
Frame6.Visible = False
End If
End Sub

Private Sub Command1_Click() ' all 8 buttons are toggle output bit with a LED status indicator.
If out7_flag = 0 And pwr_flag = 1 Then
Shape1.BackColor = &H80FF&
outport_value = outport_value Or &H80 '10000000 8th bit on
out7_flag = 1
Else
Shape1.BackColor = &HE0E0E0
outport_value = outport_value And &H7F '01111111 8th bit off
out7_flag = 0
End If
End Sub

Private Sub Command10_Click()
If tog_2 = 0 Then
tog_2 = 1
Frame5.Visible = True
Else
tog_2 = 0
Frame5.Visible = False
End If
End Sub

Private Sub Command11_Click()
If tog_1 = 0 Then
tog_1 = 1
Frame1.Visible = True
Else
tog_1 = 0
Frame1.Visible = False
End If
End Sub

Private Sub Command12_Click()
'turn off system
pwr_flag = 0
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
outport_value = &HFF   ' set output bits all to 1 or 11111111
update_output
Out control_port, &HC    '00001100 set control port pins to 0 and status byte to safe
'bit 0 strobe is inverted so we have write a 1 to get a 0 at the port pin.
Beep ' i use the beep to debug or monitor
' add some things here to set inputs and control to defaults if required
End ' exit program
End Sub

Private Sub Command13_Click()
Frame5.Visible = False
tog_2 = 0
End Sub

Private Sub Command14_Click()
Frame1.Visible = False
tog_1 = 0
End Sub

Private Sub Command2_Click()
If out6_flag = 0 And pwr_flag = 1 Then
Shape2.BackColor = &H80FF&
outport_value = outport_value Or &H40 '01000000 7th bit on
out6_flag = 1
Else
Shape2.BackColor = &HE0E0E0
outport_value = outport_value And &HBF '10111111 7th bit off
out6_flag = 0
End If
End Sub

Private Sub Command3_Click()
If out5_flag = 0 And pwr_flag = 1 Then
Shape3.BackColor = &H80FF&
outport_value = outport_value Or &H20 '00100000 6th bit on
out5_flag = 1
Else
Shape3.BackColor = &HE0E0E0
outport_value = outport_value And &HDF '11011111 6th bit off
out5_flag = 0
End If
End Sub

Private Sub Command4_Click()
If out4_flag = 0 And pwr_flag = 1 Then
Shape4.BackColor = &H80FF&
outport_value = outport_value Or &H10 '00010000 5th bit on
out4_flag = 1
Else
Shape4.BackColor = &HE0E0E0
outport_value = outport_value And &HEF '11101111 5th bit off
out4_flag = 0
End If
End Sub

Private Sub Command5_Click()
If out3_flag = 0 And pwr_flag = 1 Then
Shape5.BackColor = &H80FF&
outport_value = outport_value Or &H8  '00001000 4th bit on
out3_flag = 1
Else
Shape5.BackColor = &HE0E0E0
outport_value = outport_value And &HF7 '11110111 4th bit off
out3_flag = 0
End If
End Sub

Private Sub Command6_Click()
If out2_flag = 0 And pwr_flag = 1 Then
Shape6.BackColor = &H80FF&
outport_value = outport_value Or &H4  '00000100 3rd bit on
out2_flag = 1
Else
Shape6.BackColor = &HE0E0E0
outport_value = outport_value And &HFB '11111011 3rd bit off
out2_flag = 0
End If
End Sub

Private Sub Command7_Click()
If out1_flag = 0 And pwr_flag = 1 Then
Shape7.BackColor = &H80FF&
outport_value = outport_value Or &H2  '00000010 2nd bit on
out1_flag = 1
Else
Shape7.BackColor = &HE0E0E0
outport_value = outport_value And &HFD '11111101 2nd bit off
out1_flag = 0
End If
End Sub

Private Sub Command8_Click()
If out0_flag = 0 And pwr_flag = 1 Then
Shape8.BackColor = &H80FF&
outport_value = outport_value Or &H1  '00000001 1st bit on
out0_flag = 1
Else
Shape8.BackColor = &HE0E0E0
outport_value = outport_value And &HFE '11111110 1st bit off
out0_flag = 0
End If
End Sub

Private Sub Command9_Click() ' this is a power on-off toggle switch with LED
If pwr_flag = 0 Then           'turn on instrument
Shape10.BackColor = &HFFFF&
pwr_flag = 1
Timer1.Enabled = True
Timer2.Enabled = True
Timer3.Enabled = False
Command9.Caption = "OFF"
VScroll1.Enabled = True
VScroll2.Enabled = True
VScroll3.Enabled = True
Else
Shape10.BackColor = &H40C0& ' turn off system
pwr_flag = 0
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Command9.Caption = "ON"
start_up     ' load all values or reset or prime
End If
End Sub

Private Sub Form_Activate()
Command9.SetFocus
End Sub

Private Sub Form_Load()
Combo1.Text = "&H378"
Combo2.Text = "MVS"
start_up
End Sub

Private Sub Form_Unload(Cancel As Integer)
Command12_Click 'exit after setting ports to defaults
End Sub

Private Sub Timer1_Timer() 'this scans 7135 BUSY for a high to low transition
Dim busy_level             'when the edge is detected the data is read quickly
Out control_port, read_status
Text6 = Hex(Inp(input_port))
busy_level = Inp(input_port) And &H8
If busy_level = &H0 Then
edge_detect = edge_detect + 1 ' that means 7135 busy is high
Shape9.BackColor = &HFF& ' light a LED
Else
Shape9.BackColor = &H800000 ' off the LED if busy is low
End If
If busy_level = &H8 And edge_detect > 10 Then 'it was high for over 100ms now gone low
edge_detect = 0
Timer3.Enabled = True ' read the 4 digit data from 7135
Timer1.Enabled = False ' stop monitor of busy till reading is taken
End If
End Sub
Private Sub Timer2_Timer()
If Combo2.Text = "DPC" Then
update_output   ' this updates output port for relays every 100ms
End If
If Combo2.Text = "MVS" Then
update_output   ' this updates output port every 100ms for D-A convertor
update_output_hi ' higher byte
End If
End Sub
Sub update_output_hi()
Dim strobe_delay 'the strobe pulse latches the data to 2nd 373
strobe_delay = 10 'this sets pulse width approx update output port every 10mS
Out output_port, outport_high 'output the data to the output port
Out control_port, latch_low2 'latch the value to 2nd 373 with IC by strobing.
'150nS required put a 10uS delay here for a strobe pulse, works upto pentium 10GHz ?.
Do Until strobe_delay = 0 ' take strobe pulse low
strobe_delay = strobe_delay - 1
Loop
Out control_port, latch_high  '&H0 strobe pulse is back to high
Text10 = Hex(outport_high And &H7F) ' this is just a debug monitor of output in hex.
End Sub
Sub update_output()
Dim strobe_delay 'the strobe pulse latches the data to U6
strobe_delay = 10 'this sets pulse width approx update output port every 10mS
Out output_port, outport_value 'output the data to the output port
Out control_port, latch_low 'latch the value to the IC U6 with IC U10B by strobing.
'150nS required put a 10uS delay here for a strobe pulse, works upto pentium 10GHz ?.
Do Until strobe_delay = 0 ' take strobe pulse low
strobe_delay = strobe_delay - 1
Loop
Out control_port, latch_high  '&H0 strobe pulse is back to high
Text7 = Hex(outport_value) ' this is just a debug monitor of output in hex.
End Sub

Sub start_up()
'set printer port to power on defaults
outport_value = &HFF  ' set output bits all to 1 or 11111111
update_output
Out control_port, &HC   '00001100 set control port pins to 0 and status byte to safe
'end setting of printer port defaults
output_port = Combo1 ' put default values for printer ports
input_port = Combo1 + 1
control_port = Combo1 + 2
Text1.Text = "0x" & Hex(output_port) ' these are just feedback monitors
Text2.Text = "0x" & Hex(input_port)
Text3.Text = "0x" & Hex(control_port)
read_value = &HC ' this address makes 74LS139 select one of the 373 chips.
read_status = &H0 'same
read_digits = &H8 'same
outport_value = &H0 'set output port data going to U6 to 00000000
outport_high = &H0 'set output port higher byet to 00000000
pol_bit = 0 ' this holds the valuse for 16th D-A polarity
latch_low = &H3 ' 00000011 as AF and STB are inverted logic outputs.
latch_low2 = &H1 '00000001 to select 2nd 373 upper byte
latch_high = &H0 ' 00000000 will make STB high as STB is inverted.
out7_flag = 0
out6_flag = 0
out5_flag = 0
out4_flag = 0
out3_flag = 0
out2_flag = 0
out1_flag = 0
out0_flag = 0
'the output port status of program set to 0 later in ini file if mem required.
pwr_flag = 0 ' turn off port activity till user turns on
Timer1.Enabled = False ' off outputs and inputs to ports
Timer2.Enabled = False ' off outputs and inputs to ports
Timer3.Enabled = False ' off outputs and inputs to ports
Shape1.BackColor = &HE0E0E0 ' turn off LEDs on GUI
Shape2.BackColor = &HE0E0E0
Shape3.BackColor = &HE0E0E0
Shape4.BackColor = &HE0E0E0
Shape5.BackColor = &HE0E0E0
Shape6.BackColor = &HE0E0E0
Shape7.BackColor = &HE0E0E0
Shape8.BackColor = &HE0E0E0
edge_detect = 0 ' this flag monitors busy of 7135 and also lights a LED
Shape9.BackColor = &H800000 ' this LED indicates samples taken or BUSY of 7135
digit_1 = 0
digit_2 = 0
digit_3 = 0
digit_4 = 0
digit_5 = 0
plus_minus = "+"
d1_dun = 0
d2_dun = 0
d3_dun = 0
d4_dun = 0
d5_dun = 0
dvm_reading = plus_minus & digit_5 & digit_4 & digit_3 & digit_2 & digit_1
old_d5 = 0
old_d4 = 0
Label1.Visible = False
Label5.Visible = False
set_value = 0 ' sets value of output in a 16 bit value for D to A convertor
Text8 = 0
VScroll1.Value = 0
VScroll2.Value = 0
VScroll3.Value = 0
VScroll1.Enabled = False
VScroll2.Enabled = False
VScroll3.Enabled = False
tog_1 = 0
tog_2 = 0
End Sub

Private Sub Timer3_Timer() ' read the digit number and digit value of 7135
Dim digit_code, digit_value
digit_value = 0
digit_code = 0
Out control_port, read_digits
digit_code = Inp(input_port) And &HF0 ' 0 lower nibble
digit_code = digit_code Xor &H80 ' invert 'ack' bit
digit_code = Str(Hex(digit_code)) ' hex as string
digit_code = digit_code * 0.1 'get rid of lower nibble
Text4 = digit_code
Out control_port, read_value
digit_value = Inp(input_port) And &HF0 ' 0 lower nibble
digit_value = digit_value Xor &H80 ' invert 'ack' bit
digit_value = Str(Hex(digit_value))
digit_value = digit_value * 0.1
Text5 = digit_value
Select Case digit_code
Case 1 ' if 1st digit then store value in digit_1
 If digit_1 = digit_value Then  ' added this if statement to reject digit crossover error
 d1_dun = 2
 Else
 digit_1 = digit_value
 d1_dun = 1
 End If
Case 2 ' if 2st digit then store value in digit_2
 If digit_2 = digit_value Then
 d2_dun = 2
 Else
 digit_2 = digit_value
 d2_dun = 1
 End If
Case 4
 If digit_3 = digit_value Then
 d3_dun = 2
 Else
 digit_3 = digit_value
 d3_dun = 1
 End If
Case 8
 If digit_4 = digit_value Then
 d4_dun = 2
 Else
 digit_4 = digit_value
 d4_dun = 1
 End If
Case Else
End Select
'light up over range and under range annunciators
Dim or_fl, ur_fl
Out control_port, read_status
or_fl = Inp(input_port) And &H40 ' 0 lower nibble
or_fl = Str(Hex(or_fl))
or_fl = or_fl * 0.1
If or_fl = 4 Then
Label1.Visible = True
Else: Label1.Visible = False
End If
Out control_port, read_status
ur_fl = Inp(input_port) And &H80 ' 0 lower nibble
ur_fl = Str(Hex(ur_fl))
ur_fl = ur_fl * 0.1
If ur_fl = 8 Then
Label5.Visible = False
Else: Label5.Visible = True
End If
'get the value of digit 5
get_d5
If (d1_dun = 2) And (d2_dun = 2) And (d3_dun = 2) And (d4_dun = 2) And (d5_dun = 2) Then
' error readings race conditions or crossover reject
If digit_5 = 0 And digit_4 = 0 And old_d5 = 1 And old_d4 = 0 Then GoTo dropit
If digit_5 = 1 And digit_4 = 9 And old_d5 = 1 And old_d4 = 0 Then GoTo dropit
If digit_5 = 0 And digit_4 = 0 And old_d5 = 0 And old_d4 = 9 Then GoTo dropit
If digit_5 = 1 And digit_4 = 9 And old_d5 = 0 And old_d4 = 9 Then GoTo dropit
d5_pol ' get polarity + or -
dvm_reading = plus_minus & digit_5 & digit_4 & digit_3 & digit_2 & digit_1
old_d5 = digit_5
old_d4 = digit_4
dropit:
Timer1.Enabled = True
Timer3.Enabled = False
d1_dun = 0
d2_dun = 0
d3_dun = 0
d4_dun = 0
d5_dun = 0
End If
End Sub
Sub d5_pol()
Dim pol_fl
pol_fl = 0
Out control_port, read_status
pol_fl = Inp(input_port) And &H20 ' 0 lower nibble
pol_fl = Str(Hex(pol_fl))
pol_fl = pol_fl * 0.1
If pol_fl = 2 Then
plus_minus = "+"
Else: plus_minus = "- "
End If
End Sub
Sub get_d5() ' get d5 value 1 or 0 digit 5
Dim d5_fl, dgt_val
d5_fl = 0
dgt_val = 0
Out control_port, read_status
d5_fl = Inp(input_port) And &H10 ' 0 lower nibble
d5_fl = Str(Hex(d5_fl))
d5_fl = d5_fl * 0.1
If d5_fl = 1 Then
Out control_port, read_value
dgt_val = Inp(input_port) And &HF0 ' 0 lower nibble
dgt_val = dgt_val Xor &H80 ' invert 'ack' bit
dgt_val = Str(Hex(dgt_val))
dgt_val = dgt_val * 0.1
End If
If dgt_val = 1 And d5_fl = 1 And digit_5 = 1 Then    ' added this if statement to reject digit crossover error
d5_dun = 2
ElseIf dgt_val = 0 And d5_fl = 1 And digit_5 = 0 Then
d5_dun = 2
Else
digit_5 = dgt_val
d5_dun = 1
End If
End Sub

Private Sub VScroll1_Change()
output_word
End Sub

Private Sub VScroll2_Change()
output_word
End Sub

Private Sub VScroll3_Change()
output_word
End Sub

Sub output_word()
set_value = VScroll1.Value + VScroll2.Value + VScroll3.Value
Text8 = set_value
If Combo2.Text = "MVS" Then
If set_value < 0 Then
pol_bit = 1 ' set pol_bit high then 16th bit of the word will be high
set_value = set_value * -1 ' 16th bit selects a diffrent op07
Else
pol_bit = 0
End If
outport_high = set_value And &HFF00 ' 00 lower byte
outport_high = outport_high / &HFF ' remove trailing  00 in hex
If pol_bit = 1 Then
outport_high = outport_high Or &H80 'add a polarity bit on the 16th bit 1 is negative
End If
outport_value = set_value And &HFF
Text9 = Hex(set_value)
Text11 = pol_bit
End If
End Sub
